﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MastePage/SubEmptyMaster.Master" AutoEventWireup="true" CodeBehind="MatReturnAdd.aspx.cs" Inherits="BySoft.Web.Site.StockManage.MatReturnAdd" %>

<%@ MasterType VirtualPath="~/MastePage/SubEmptyMaster.Master" %>
<%@ Register Assembly="OneSoft.Web" Namespace="OneSoft.Web.UI.WebControls" TagPrefix="asp" %>
<%@ Register Src="../UserControl/SuggestTextBox2.ascx" TagName="SuggestTextBox2"
    TagPrefix="uc1" %>
<%@ Register Assembly="BySoft.Web.Controls" Namespace="BySoft.Web.Controls" TagPrefix="cc1" %>
<asp:Content ID="cphHeadContent" runat="server" ContentPlaceHolderID="EmptyMasteCPH">
    <script language="javascript" type="text/javascript">
        $(function () {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        });

        function Refreashtab() {
            $("#tabs").tabs({ show: function (event, ui) { iframeAutoFit(); } });
        }


        function importNewRow() {
            var strMatReturnID = $("#<%=lblBillID.ClientID%>").text();
            ShowTopDialog('新增', '../ComPage/QueryMMaterialMatReturn.aspx?matreturnid=' + encodeURIComponent(strMatReturnID), 'NewDetail();', 800, 600); return false;
        }

        function NewDetail() {
            var str = getCookie(dialogReturn_key);
            if (str != null && str == "success") {
                $("#<%=btnAddh.ClientID %>").click();
        }
        setCookie(dialogReturn_key, "");
    }

    function CheckNumWithDotOne(txtBox) {
        if (txtBox != null && txtBox.value != "") {
            var numFormat = /(^[0-9]\d{0,9}(\.\d{0,4})?$)/;
            var text = txtBox.value;
            if (!numFormat.test(text)) {
                txtBox.value = 0;
            }
        }
    }
    </script>

    <h1 class="tit">库存管理 >> <a href="MatReturnList.aspx">材料退货单</a> >> 新增</h1>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <div class="tableStyle2">
                <table cellpadding="0" cellspacing="0" id="tBase" runat="server">
                    <tr>
                        <th class="left2">表单号码：
                        </th>
                        <td class="right2">
                            <asp:Label CssClass="lblreadonly" ID="lblBillID" runat="server"></asp:Label>
                        </td>
                        <th class="left2">日期：
                        </th>
                        <td class="right2">
                             <input class="Wdate" id="cpBillDate" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" readonly="true" runat="server" type="text"></input>
                        </td>
                    </tr>
                    <tr>
                        <th class="left2">退货理由：</th>
                        <td class="right2">
                           <asp:DropDownList ID="ddlReturnReason" runat="server"></asp:DropDownList>
                        </td>
                        <th class="left2"></th>
                        <td class="right2"></td>
                    </tr>
                </table>
            </div>
            <div class="tableStyle">
                <div id="tabs">
                    <ul>
                        <li><a href="#tabs-1">明细</a></li>
                    </ul>
                    <div id="tabs-1" class="tableStyle">
                        <div style="text-align: right; width: 100%; padding-bottom: 10px">
                            <label class="btnStylec png_bg">
                                <input type="button" id="btnAdd" value="添加" onclick="importNewRow()" />
                            </label>
                            <label class="btnStylec png_bg">
                                <asp:Button ID="btnAddh" runat="server" CssClass="Hidden" OnClick="btnAddh_Click" />
                            </label>
                        </div>
                        <div class="divscroll">
                            <asp:SGridView runat="server" ID="grdResult" Width="100%" ShowActionToolBar="false"
                                OnRowDataBound="grdResult_RowDataBound" OnRowCommand="grdResult_RowCommand" AutoGenerateColumns="false"
                                AllowCascade="false">
                                <Columns>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            BillDetailID
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblBillDetailID" runat="server" Text='<%#Eval("BillDetailID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            单件毫米数
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblSingleMMNumber" runat="server" Text='<%#Eval("SingleMMNumber") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            剩余数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblLeftNums" runat="server" Text='<%#Eval("LeftNums") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            序号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <%# Container.DisplayIndex+1 %>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderStyle-CssClass="Hidden" ItemStyle-CssClass="Hidden" FooterStyle-CssClass="Hidden">
                                        <HeaderTemplate>
                                            MatInStockDetailID
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMatInStockDetailID" runat="server" Text='<%#Eval("MatInStockDetailID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            入库单号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMatInStockID" runat="server" Text='<%#Eval("MatInStockID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            原料编号
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMaterialID" runat="server" Text='<%#Eval("MaterialID") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            原料品名
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblMaterialName" runat="server" Text='<%#Eval("MaterialName") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            规格
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblSpecifications" runat="server" Text='<%#Eval("Specifications") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            单位
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblUnit" runat="server" Text='<%#Eval("Unit") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            来料数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="lblInStockNum" runat="server" Text='<%#Eval("InStockNum") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            退回数量
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtNums" runat="server" Text='<%#Eval("Nums") %>' onkeyup="CheckNumWithDotOne(this);changeNum(this);"></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderTemplate>
                                            退回毫米数
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:TextBox ID="txtMMNumber" runat="server" Text='<%#Eval("MMNumber") %>' onkeyup="CheckNumWithDotOne(this);"></asp:TextBox>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField>
                                        <HeaderStyle Width="35px" />
                                        <ItemStyle Width="35px" />
                                        <HeaderTemplate>
                                            删除
                                        </HeaderTemplate>
                                        <ItemTemplate>
                                            <asp:ImageButton ImageUrl="~/App_Themes/Common_CSS/images/delete_small.gif" runat="server"
                                                ID="ibtnDel" /><asp:Button ID="btnDel" runat="server" CssClass="Hidden" CommandArgument='<%#Eval("MatInStockDetailID") %>'
                                                    CommandName="del" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                            </asp:SGridView>
                        </div>
                    </div>
                </div>
            </div>
            <div class="controlBar" align="center">
                <table cellpadding="0" cellspacing="0" style="width: 300px; margin: 0 auto;">
                    <tr>
                        <td colspan="4">
                            <label class="btnStyleb png_bg">
                                <asp:Button ID="btnSubmit" runat="server" Text="确定"
                                    OnClick="btnSubmit_Click" ValidationGroup="gSubmit" />
                            </label>
                            <label class="btnStylec png_bg">
                                <input type="button" id="Button2" value="返回" runat="server" onclick="window.location = 'MatReturnList.aspx'" />
                            </label>
                        </td>
                    </tr>
                </table>
            </div>
            <script language="javascript" type="text/javascript">
                function changeNum(obj) {
                    var strBase = "txtNums";
                    var pre = obj.id.replace(strBase, "");
                    var dNums = $("#" + pre + strBase).val() * 1;
                    var dLeftNums = $("#" + pre + "lblLeftNums").text() * 1;

                    if (dNums > dLeftNums) {
                        $("#" + pre + strBase).val(dLeftNums);
                    }
                    var dMMNumber = $("#" + pre + strBase).val() * $("#" + pre + "lblSingleMMNumber").text();
                    dMMNumber = dMMNumber.toFixed(2);
                    $("#" + pre + "txtMMNumber").val(dMMNumber);
                }
            </script>
        </ContentTemplate>
    </asp:UpdatePanel>
</asp:Content>
